import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:studymanage/util/request.dart';

class Protocol extends StatefulWidget {
  final agree;
  final readOnly;
  Protocol(this.agree,{this.readOnly});

  @override
  State<StatefulWidget> createState() {
    return ProtocolState();
  }
}

class ProtocolState extends State<Protocol>{
  String _content = '';


  @override
  void initState() {
    Request().post("/multiapi/open/c186v_protocol").then((response){
      setState(() {
        _content = response.data['content'];
      });
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        brightness: Brightness.light,
        title: Text('用户协议',
          style: TextStyle(
            fontFamily: 'PingFangSC-Medium',
            fontSize: ScreenUtil().setSp(16),
            fontWeight: FontWeight.w600,
            color: Color.fromRGBO(51, 51, 51, 1),
            height: 1,
          ),
        ),
        backgroundColor: Colors.white,
        centerTitle: true,
        leading: FlatButton(
          child: Icon(
            Icons.arrow_back_ios,
            size: ScreenUtil().setSp(16),
            color: Color.fromRGBO(51, 51, 51, 1),
          ),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Container(
              width: MediaQuery.of(context).size.width,
              padding: EdgeInsets.only(
                left: ScreenUtil().setWidth(19.5),
                right: ScreenUtil().setWidth(19.5),
                top: ScreenUtil().setHeight(25),
              ),
              decoration: BoxDecoration(
                border: Border(
                  top: BorderSide(
                    color: Color.fromRGBO(248, 248, 248, 1),
                    width: ScreenUtil().setHeight(7.5),
                  ),
                ),
              ),
              child: Text(
                _content,
                style: TextStyle(
                  fontFamily: 'PingFangSC-Light',
                  fontSize: ScreenUtil().setSp(14),
                  fontWeight: FontWeight.w300,
                  color: Color.fromRGBO(51, 51, 51, 1),
                  height: 1.85,
                ),
                textAlign: TextAlign.justify,
              ),
            ),
            Offstage(
              offstage: widget.readOnly != null,
              child: Container(
                width: MediaQuery.of(context).size.width,
                height: ScreenUtil().setHeight(44),
                margin: EdgeInsets.only(
                  top: ScreenUtil().setHeight(50),
                  bottom: ScreenUtil().setHeight(20),
                ),
                padding: EdgeInsets.only(
                  left: ScreenUtil().setWidth(15),
                  right: ScreenUtil().setWidth(15),
                ),
                child: FlatButton(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(ScreenUtil().setHeight(4)),
                    ),
                  ),
                  color: Color.fromRGBO(210, 180, 142, 1),
                  child: Text('阅读并同意',
                    style: TextStyle(
                      fontFamily: 'PingFangSC-Regular',
                      fontSize: ScreenUtil().setSp(16),
                      color: Colors.white,
                    ),
                  ),
                  onPressed: () {
                    widget.agree();
                    Navigator.pop(context);
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}